// ==============================================
// InetAddress Example
// make : pwg
// date : 2003
// note : 지정된 도메인의 IP주소 알아내기
// ==============================================
package l_network;

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;

public class InetAddressEx extends JFrame implements ActionListener {
	TextField textDomain;
	Button button;
	TextArea resultIp;

	InetAddress address;

	Container cont;

	public InetAddressEx() {
		cont = this.getContentPane();
		cont.setLayout(null);

		this.setSize(400, 300);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		initForm();
	}

	public void initForm() {
		setTitle("InetAddress Example");

		textDomain = new TextField();
		textDomain.setBounds(30, 30, 200, 20);

		button = new Button("IP Address");
		button.setBounds(235, 30, 120, 20);
		button.addActionListener(this);

		resultIp = new TextArea();
		resultIp.setBounds(30, 60, 330, 180);

		cont.add(textDomain);
		cont.add(button);
		cont.add(resultIp);
	}

	public void actionPerformed(ActionEvent e) {
		String str = textDomain.getText();
		resultIp.setText("");
		try {
			address = InetAddress.getByName(str);

			resultIp.append("Domain    = " + str + "\n");
			resultIp.append("ip        = " + address.getHostAddress() + "\n");
			resultIp.append("Host name = " + address.getHostName() + "\n");

			if (address.isMulticastAddress())
				resultIp.append(" is Multicast \n\n");

			resultIp.append("--------------------------\n");
			String ip = InetAddress.getLocalHost().getHostAddress();
			resultIp.append("Local Host = " + ip + "\n");
			resultIp.append("--------------------------\n");

		} catch (UnknownHostException ex) {
			resultIp.append("error \n");

		}
	}

	public static void main(String args[]) {
		InetAddressEx f = new InetAddressEx();

	}

}
